<template>
    <c-list-template title="仓库配置" :operation="true">
        <template slot="search">
            <el-row :gutter="5">
                <el-col :span="6" class="flex-center ">
                    <div class="mr-lg">仓库名称</div>
                    <el-input v-model="querys.name" placeholder="请输入仓库名称" class="wh flex-1 mr-lg" />
                </el-col>
                <el-col :span="18" class="flex-x-end">
                    <el-button icon="el-icon-search" type="primary" @click="handleSelect">搜索</el-button>
                    <el-button icon="el-icon-delete" @click="handleReset">重置</el-button>
                </el-col>
            </el-row>
        </template>
        <template slot="operation">
            <div class="flex-y-center">
                <el-button icon="el-icon-plus" type="primary" @click="handleAdd">新增</el-button>
                <el-button icon="el-icon-download" type="primary" @click="handleDownloadTemplate">下载模板</el-button>
                <c-upload-excel action="/StoreInfo/importExcel" @change="handleSelect" class="ml-sm" />
            </div>
        </template>
        <template slot="list">
            <el-table :header-cell-style="{ background: '#F1F1F1', color: '#092132' }" :data="tableData" v-loading="loading">
                <el-table-column label="序号" align="center" width="80" type="index" />
                <el-table-column width="200" label="仓库名称" align="left" prop="name" />
                <el-table-column width="200" label="国家" align="left" prop="addressCountry" />
                <el-table-column width="200" label="城市" align="left" prop="addressCity" />
                <el-table-column width="" label="仓库地址" align="left">
                    <template slot-scope="scope">
                        {{scope.row.addressArea}} {{scope.row.addressDetails}}
                    </template>
                </el-table-column>
                <!-- <el-table-column label="入库费（元）" align="right">
                    <template slot-scope="scope">
                        {{scope.row.feeIn | thousands}}
                    </template>
                </el-table-column>
                <el-table-column label="出库费（元）" align="right">
                    <template slot-scope="scope">
                        {{scope.row.feeOut | thousands}}
                    </template>
                </el-table-column>

                <el-table-column width="150" label="仓储费（元 / 天）" align="right">
                    <template slot-scope="scope">
                        {{scope.row.charge | thousands}}
                    </template>
                </el-table-column>

                <el-table-column width="150" label="联系人" align="center" prop="contactPerson" /> -->
                <el-table-column width="200" label="创建时间" align="center">
                    <template slot-scope="scope">
                        {{ scope.row.timeCreate | dateYMDHMSFormat }}
                    </template>
                </el-table-column>
                <el-table-column width="150" label="操作" align="center">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="handleDetails(scope.row)" :underline="false">编辑</el-link>
                        <el-link class="ml-lg" @click="handleDel(scope.row)" type="danger" :underline="false">删除</el-link>
                    </template>
                </el-table-column>
            </el-table>
        </template>
        <template slot="pagination">
            <el-pagination background :current-page="querys.current" :page-sizes="[10, 20, 50, 100]" :page-size="querys.size" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange" @current-change="handleCurrentChange" />
        </template>
        <c-warehouse-form ref="cWarehouseForm" />
    </c-list-template>
</template>
<script>
import cWarehouseForm from "./components/c-warehouse-form.vue";
export default {
    components: {
        cWarehouseForm,
    },
    data () {
        return {
            total: 0,
            tableData: [],
            querys: {
                current: 1,
                size: 10,
            },
            loading: false,
        };
    },
    mounted () {
        this.tableList();
    },
    methods: {
        handleDownloadTemplate () {
            this.loading = true;
            const url = "/StoreInfo/download";
            this.$download({ url }).then((res) => {
                this.fileExport(res, "仓库信息模板");
                this.loading = false;
            });
        },
        handleDel (item) {
            this.$confirm("此操作将永久删除该信息, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                const url = "/StoreInfo/delete";
                this.$post({ url, params: { id: item.id } }).then((res) => {
                    this.$message.success("删除成功");
                    this.tableList();
                });
            });
        },
        handleDetails (item) {
            this.$refs.cWarehouseForm.handleOpen(item);
        },
        handleAdd () {
            this.$refs.cWarehouseForm.handleOpen();
        },
        tableList () {
            this.loading = true;
            const params = JSON.parse(JSON.stringify(this.querys));
            const url = "/StoreInfo/page";
            this.$get({ url, params }).then((res) => {
                this.tableData = res.records;
                this.total = res.total * 1;
                this.loading = false;
            });
        },
        handleReset () {
            this.querys = {
                current: 1,
                size: 10,
            };
            this.tableList();
        },
        handleSelect () {
            this.querys.current = 1;
            this.tableList();
        },
        handleSizeChange (val) {
            this.querys.size = val;
            this.tableList();
        },
        handleCurrentChange (val) {
            this.querys.current = val;
            this.tableList();
        },
    },
};
</script>
